home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / mail / uniqmail < prev   
Encoding:
AWK Script  |  1997-08-26  |  1.6 KB  |  79 lines

  1. #!/usr/local/bin/gawk -f
  2. #!/usr/bin/awk -f
  3. # @(#) uniqmail.gawk 1.0 94/03/09
  4. # 91/03/25 john h. dubois iii (john@armory.com)
  5. # 92/02/17 added help
  6. # 92/03/12 replaced incorrect continues with nexts
  7. # 92/05/02 converted to #!awk script
  8. # 94/03/09 Use gawk so - options can be given
  9.  
  10. BEGIN {
  11.     if (ARGV[1] ~ "^[-+]h$") {
  12.     print \
  13. "uniqmail: delete messages with identical message-ids from mailx files.\n" \
  14. "Usage: uniqmail [-h] [mailx-file ...]\n" \
  15. "uniqmail reads messages from the specified files (or the standard input if\n" \
  16. "not filenames are given), and writes them to the standard output.\n" \
  17. "The Message-Id: line in the header of each message is checked against\n" \
  18. "those of all messages previously written.  If the Message-Id: is the same,\n" \
  19. "the message is discarded."
  20.     exit(0)
  21.     }
  22.     sep = "\01\01\01\01"
  23.     InHeader = 1
  24.     msgid = ""
  25.     Skip = 0
  26.     Header = ""
  27. }
  28.  
  29. ($0 == sep) && InHeader {
  30.     next
  31. }
  32.  
  33. true {
  34.     printf("InHeader: %s\nLine: %s\nHeader: %s\n",InHeader,$0,Header)
  35. }
  36.  
  37. # Found end of header
  38. InHeader && ((NF == 0) || $0 == sep) {
  39.     InHeader = 0
  40.     if (Header == "") {
  41.     print "Skipping message with no header." | "cat 1>&2"
  42.     Skip = 1
  43.     next
  44.     }
  45.     if ((msgid != "") && (msgid in msgids)) {
  46.     print "Skipping duplicate message with id " msgid | "cat 1>&2"
  47.     Skip = 1
  48.     next
  49.     }
  50.     msgids[msgid]
  51.     printf("%s\n",sep)
  52.     printf "%s\n",Header
  53.     Header = ""
  54.     Skip = 0
  55.     next
  56. }
  57.  
  58. $0 == sep {
  59.     print sep
  60.     InHeader = 1
  61.     msgid = ""
  62.     Header = ""
  63.     next
  64. }
  65.  
  66. # get Message-Id
  67. (InHeader == 1) && ($1 ~ "^Message-[iI][dD]:$") {
  68.     msgid = $2
  69. }
  70.  
  71. (InHeader == 1) {
  72.     Header = Header $0 "\n"
  73.     next
  74. }
  75.  
  76. !Skip {
  77.     print $0
  78. }
  79.